From 124e8d3c51d15b64da5aa4373033eee0fec5f543 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 18 Jan 2015 21:02:25 -0800 Subject: [PATCH] Fix nightly and improve merge error message The nightly bots are all failing because a nightly build emits a .cargo/config which uses `[target]` for some overrides, but a test was creating invalid configuration for `[target]`, causing the test error message to change. This commit fixes the test by using a different error message (which should not conflict). It also improves the error message for "configuration could not be merged" to include more contextual information about what just happened. --- src/cargo/util/config.rs | 17 +++++++++++++++-- tests/test_bad_config.rs | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 46bb6915d..ae36e427d 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -273,8 +273,21 @@ impl ConfigValue { (&mut CV::Table(ref mut old, _), CV::Table(ref mut new, _)) => { let new = mem::replace(new, HashMap::new()); for (key, value) in new.into_iter() { - match old.entry(key) { - Occupied(mut entry) => { try!(entry.get_mut().merge(value)); } + match old.entry(key.clone()) { + Occupied(mut entry) => { + let path = value.definition_path().clone(); + let entry = entry.get_mut(); + try!(entry.merge(value).chain_error(|| { + human(format!("failed to merge key `{}` between \ + files:\n \ + file 1: {}\n \ + file 2: {}", + key, + entry.definition_path().display(), + path.display())) + + })); + } Vacant(entry) => { entry.insert(value); } }; } diff --git a/tests/test_bad_config.rs b/tests/test_bad_config.rs index 3b23fd3ff..4597ae763 100644 --- a/tests/test_bad_config.rs +++ b/tests/test_bad_config.rs @@ -1,4 +1,4 @@ -use support::{project, execs}; +use support::{project, execs, cargo_dir}; use hamcrest::assert_that; fn setup() {} @@ -13,11 +13,13 @@ test!(bad1 { "#) .file("src/lib.rs", "") .file(".cargo/config", r#" - target = "foo" + [target] + nonexistent-target = "foo" "#); - assert_that(foo.cargo_process("build").arg("-v"), + assert_that(foo.cargo_process("build").arg("-v") + .arg("--target=nonexistent-target"), execs().with_status(101).with_stderr("\ -expected table for configuration key `target`, but found string in [..]config +expected table for configuration key `target.nonexistent-target`, but found string in [..]config ")); }); @@ -88,6 +90,32 @@ expected a string, but found a boolean in [..]config ")); }); +test!(bad5 { + let foo = project("foo") + .file(".cargo/config", r#" + foo = "" + "#) + .file("foo/.cargo/config", r#" + foo = 2 + "#); + foo.build(); + assert_that(foo.process(cargo_dir().join("cargo")).arg("new") + .arg("-v").arg("foo").cwd(foo.root().join("foo")), + execs().with_status(101).with_stderr("\ +Failed to create project `foo` at `[..]` + +Caused by: + Couldn't load Cargo configuration + +Caused by: + failed to merge key `foo` between files: + file 1: [..]foo[..]foo[..]config + file 2: [..]foo[..]config + +Caused by: + expected integer, but found string +")); +}); test!(bad_cargo_config_jobs { let foo = project("foo") -- 2.30.2